package com.example.controller;

import cn.hutool.core.util.ObjectUtil;
import com.example.common.AutoLog;
import com.example.common.Result;
import com.example.pojo.Carousel;
import com.example.pojo.Params;
import com.example.service.CarouselService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@CrossOrigin
@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Resource
    private CarouselService carouselService;

    @AutoLog("更新日志操作")
    @PostMapping
    public Result update(@RequestBody Carousel carousel) {
        if (ObjectUtil.isEmpty(carousel.getId())) {
            carouselService.add(carousel);
        } else {
            carouselService.update(carousel);
        }
        return Result.success();
    }

    @GetMapping("/search")
    public Result findAll(Params params) {
        PageInfo<Carousel> info = carouselService.findAll(params);
        return Result.success(info);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        carouselService.delete(id);
        return Result.success();
    }

}